package com.ebelter.seneo.ui.fragments.infos;


import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.ebelter.btcomlib.common.IOrder;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.fragments.main.Info_Fragment;
import com.ebelter.seneo.ui.views.LevelView;
import com.ebelter.seneo.utils.SeneoUtils;


//填写密码
public class Info_Bonemineralcontent_Fragment extends BaseFragment  implements Info_Fragment.IInfoUpdateInterface {

    public static final String TAG = "Info_Bonemineralcontent_Fragment";
    TextView infofly_value_tv;
    TextView infofly_valueunit_tv;
    TextView infofly_tip1_tv;
    LevelView info_levelview;

    @Override
    protected int setLayoutResouceId() {
        return R.layout.info_fly1;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        infofly_value_tv=findViewById(R.id.infofly_value_tv);
        infofly_valueunit_tv=findViewById(R.id.infofly_valueunit_tv);
        infofly_tip1_tv=findViewById(R.id.infofly_tip1_tv);
        info_levelview=findViewById(R.id.info_levelview);
    }


    @Override
    protected void initData(Bundle arguments) {

        String tip=getString(R.string.str_Bone_mineral_content_introduce);
        infofly_tip1_tv.setText(tip);

        int unit = SeneoUtils.getUnitModel();
        ViewUtils.setTextViewStr(infofly_valueunit_tv, unit==0? IUserContant.IDIS.kg:IUserContant.IDIS.lb);

        //执行了这一句 下面的UpdateCurrentMesureInfo接口会回调display方法
        if (getParentFragment()!=null){
            ((Info_Fragment)getParentFragment()).getCurrentDisplayInfo(TAG);
        }
    }



    @Override
    public void UpdateCurrentMesureInfo(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        disBone(currentUserinfos,currentMeasureRecord);
    }


    final int[] colors = new int[]{
            Color.parseColor("#49D8F1"),
            Color.parseColor("#54BF4B"),
            Color.parseColor("#EFB847")
    };
    String[] buttoms=new String[]{
            StringUtils.getResStr(R.string.piandi),
            StringUtils.getResStr(R.string.biaozhun),
            StringUtils.getResStr(R.string.piangao)};

    float[] middleKg = new float[]{53.5f,66.5f};
    float[] middleLb = new float[]{53.5f,66.5f};
    private void disBone(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        if (info_levelview==null||currentUserinfos==null)return;
        dealMiddleValue(currentUserinfos);
        int unit = SeneoUtils.getUnitModel();

        if (unit==0){
            info_levelview.setDisInfo(middleKg,colors,buttoms);
            info_levelview.setMinMaxValuse(0,8);
        }else {
            info_levelview.setDisInfo(middleLb,colors,buttoms);
            info_levelview.setMinMaxValuse(0,17);
        }


        if (currentMeasureRecord!=null){
            if (currentMeasureRecord.boneVolume!=0){
                info_levelview.setDrawWujiaoxin((true));
                ViewUtils.setTextViewStr(infofly_value_tv,currentMeasureRecord.boneVolume+"");
            }else if (currentMeasureRecord.boneVolume == 0){
                info_levelview.setDrawWujiaoxin((false));
                ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
            }
            info_levelview.displayValue(currentMeasureRecord.boneVolume);
        }else {
            info_levelview.setDrawWujiaoxin((false));
            info_levelview.displayValue(0);
            ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
        }



    }

    private void dealMiddleValue(SeneoUserinfos currentUserinfos) {
        float value;
        if (currentUserinfos.sex==0){
            if (currentUserinfos.currentWeight>=75){
                value=3.2f;
            }else if (currentUserinfos.currentWeight>=60&&currentUserinfos.currentWeight<75){
                value=2.9f;
            }else {
                value=2.5f;
            }
        }else {
            if (currentUserinfos.currentWeight>=60){
                value=2.5f;
            }else if (currentUserinfos.currentWeight>=45&&currentUserinfos.currentWeight<60){
                value=2.2f;
            }else {
                value=1.8f;
            }
        }
        float min = value*0.85f;
        float max = value*1.15f;

        middleKg[0]=NumUtils.numBaoLiuWei1(min);
        middleKg[1]=NumUtils.numBaoLiuWei1(max);
        middleLb[0]= NumUtils.numBaoLiuWei1(SeneoUtils.kg2lb(middleKg[0]));
        middleLb[1]= NumUtils.numBaoLiuWei1(SeneoUtils.kg2lb(middleKg[1]));
    }
}
